<?php

namespace app\index\model;

use think\Model;

class Sign extends Model
{
	public function getSignInfo()
	{

		$info =[
			'is_login'=>session('user')?true:false,
			'num'=>0,
			'is_sign'=>false,
			'kiss'=>5
		];


		if(session('user')){

			$user = $this->where('user_id',session('user')->user_id)->where('sign_time','>',strtotime(date('Y-m-d')))->find();

			if($user){
				$info['is_sign'] = true;

				$info['num'] = $user->sign_num;

				$info['kiss'] = $this->getKiss($user->sign_num);
			}else{

				$user = $this->where('user_id',session('user')->user_id)->where('sign_time','>',strtotime(date('Y-m-d'))-86400)->find();


				if($user){
					$info['num'] = $user->sign_num;
					$info['kiss'] = $this->getKiss($user->sign_num+1);
				}

			}
		}

		return $info;

	}

	public function getKiss($num)
	{

		if($num<5){
			return 5;
		}elseif($num<10){
			return 10;
		}elseif($num<15){
			return 15;
		}else{
			return 20;
		}
	}

}